﻿using System.Security.Cryptography.X509Certificates;

namespace LeastSquares
{   
    /// <summary>
    /// 最小二乘法
    /// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {
            //创建年份的集合 year对应为int类
            List<int> yearList = new List<int>();
            for (int i = 2007; i <= 2020; i++)
            {
                yearList.Add(i);
            }
            //创建每年GDP的集合
            List<double> GDPList = new List<double>()
            {               
                3550342737009, 4594307032667, 5101703073088, 6087163874510,
                7551500124197, 8532229986993, 9570406235659, 10475682920597,
                11061553079871, 11233276536744, 12310409370894, 13894817549380,
                14279937500608, 14687673892882
            };
            //用户输入年份
            Console.WriteLine("请输入预测年份");
            var x = Convert.ToInt32(Console.ReadLine());
            double y=0;
            double yreal = 17734062645371;
            //调用最小二乘法函数
            //代入2021年份，并与真实值进行比较，计算(y-yreal)/y*100%
            y = LeastSquaresMethod.Models.LeastSquaresMethod(yearList, GDPList, y, x);
            Console.WriteLine($"{x}年预测结果为{y}，真实值为{yreal}");
            Console.WriteLine($"差值百分比为{((y-yreal)/y)*100}%");
            Console.ReadKey();
        }          
    }
}